<!DOCTYPE html>
<html lang="zh-CN">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <script>
      const list = [
        { id: 100, name: '外套', price: 199, time: new Date('2010-08-12') },
        { id: 101, name: '裤子', price: 34, time: new Date('2013-09-01') },
        { id: 102, name: '鞋', price: 25.4, time: new Date('2018-11-22') },
        { id: 103, name: '头发', price: 19900, time: new Date('2020-12-12') },
      ]

      let sum = 0
      list.forEach((item) => {
        sum += item.price
      })
      console.log('求和结果', sum)

      // reduce 数组方法
      const sum2 = list.reduce((sum, item) => {
        return sum += item.price
      }, 0)
      console.log('求和结果2', sum2)

      const sum3 = list.reduce((sum, item) => sum += item.price , 0)
      console.log('求和结果3', sum3)
    </script>
  </body>
</html>
